﻿using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace EntityFrameworkCore1
{
    public class MyDbContext : DbContext
    {
        public DbSet<Book> Books { get; set; }
        public DbSet<Person> Persons { get; set; }
        public DbSet<Dog> Dogs { get; set; }
        public DbSet<Cat> Cats { get; set; }

        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            //Data Source = Localhost; Database = jiaoyui; User ID = sa; Password = 123456
            //Server =.; Database = demo1; Trusted_Connection = True; MultipleActiveResultSets = true
            string connStr = "Data Source=.;Initial Catalog=demo1;User ID=sa;Password=123456;TrustServerCertificate=True";
            //@"Server=DESKTOP-5QSNE38\xu(xu);Database=demo"
            optionsBuilder.UseSqlServer(connStr);
        }

        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            base.OnModelCreating(modelBuilder);
            //从当前程序集(MyDbContext)加载所有的XXXConfig: IEntityTypeConfiguration<XXX>
            modelBuilder.ApplyConfigurationsFromAssembly(this.GetType().Assembly);
        }
    }
}
